package com.example.teamtribe.common.model;

import com.example.teamtribe.common.Back;
import com.example.teamtribe.common.CallbackStore;
import com.example.teamtribe.utils.HttpUtil;
import com.example.teamtribe.utils.URLStore;

import java.util.HashMap;
import java.util.Map;

public class RelationModel {

    private static RelationModel instance;
    private RelationModel() {}
    public static RelationModel getInstance() {
        if (instance == null) {
            synchronized (RelationModel.class) {
                if (instance == null) {
                    instance = new RelationModel();
                }
            }
        }
        return instance;
    }

    /**
     *
     * @param mode 0加好友请求，1加社团请求
     * @param id 用户id，社团id
     */
    public void request(int mode, String token, int id, String reason, final Back back) {
        Map<String, String> params = new HashMap<>();
        params.put("TeamTribeToken", token);
        String idKey = "id";
        String url = URLStore.RELATION_REQUEST_SEND;
        if (mode == 1) {
            idKey = "teamId";
            url = URLStore.TEAM_REQUEST_SEND;
        }
        params.put(idKey, id + "");
        params.put("reason", reason);
        HttpUtil.post(url, params, CallbackStore.getCallback(back));
    }

    public void response(String token, int id, int result, String reason, final Back back) {
        Map<String, String> params = new HashMap<>();
        params.put("TeamTribeToken", token);
        params.put("id", id + "");
        params.put("result", result + "");
        params.put("reason", reason);
        HttpUtil.post(URLStore.RELATION_RESPONSE, params, CallbackStore.getCallback(back));
    }

}
